/*
https://www.luogu.com.cn/problem/P1123
*/
#include<iostream>
#include<cstring>
using namespace std;
int d[8][2] = { 1,0,-1,0,0,1,0,-1,1,1,-1,1,1,-1,-1,-1 };
int t, n, m, s[8][8], vis[8][8], ans, mx;
void dfs(int x, int y) {
    if (y > m) {
        dfs(x + 1, 1);
        return;
    }
    if (x > n) {
        mx = max(mx, ans);
        return;
    }
    dfs(x, y + 1);
    if (vis[x][y] == 0) {
        ans += s[x][y];
        for (int xx = 0; xx < 8; ++xx) {
            ++vis[x + d[xx][0]][y + d[xx][1]];
        }
        dfs(x, y + 1);
        for (int xx = 0; xx < 8; ++xx) {
            --vis[x + d[xx][0]][y + d[xx][1]];
        }
        ans -= s[x][y];
    }
}
int main()
{
    cin >> t;
    while (t--)
    {
        memset(s, 0, sizeof(s));
        memset(vis, 0, sizeof(vis));
        cin >> n >> m;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= m; ++j)
                cin >> s[i][j];
        }
        mx = 0;
        dfs(1, 1);
        cout << mx << endl;
    }
    return 0;
}